import polars as pl
from scipy.stats import f_oneway, levene

df = pl.read_csv(r"B Chapter 08\B C 08_3.csv")

pass_check = lambda p: p >= 0.05

x1 = df.filter(pl.col("group") == "0.5U").select("value")
x2 = df.filter(pl.col("group") == "1U").select("value")
x3 = df.filter(pl.col("group") == "2U").select("value")

# 检测方差齐性

stats, p_value = levene(x1, x2, x3)
passed = pass_check(p_value)

print(f"Levene test: stats={stats}, {p_value=}, {passed=}")

stats, p_value = f_oneway(x1, x2, x3)
passed = pass_check(p_value)

print(f"Oneway ANOVA: F={stats}, {p_value=}, {passed=}")
